package day05;

import java.util.Arrays;

//数组的复制
public class ArrayCopyDemo {
    public static void main(String[] args) {
         /*
        // System.arraycopy(); 此种复制方法灵活性高
        int[] a = {10,20,30,40,50};
        int[] b = new int[6];//0,0,0,0,0,0
        System.arraycopy(a,0,b,2,3);
        //a: 源数组
        //0: 原数组的起始下标
        //b: 目标数组
        //2: 目标数组的起始下标
        //4: 要复制的元素数
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);
        }

        int[] a = {9,15,8,6,3,7,5};
        int[] b = new int[10];
        System.arraycopy(a,3,b,4,4);
        for (int i = 0; i < b.length; i++) {
            System.out.println(b[i]);//0,0,0,0,6,3,7,5,0,0
        }
        */

        // Arrays.copyOf(); 此种数组复制方法灵活性差, 此种方法可以用来扩容数组
        int[] a = {10,20,30,40,50,60,70,80,90};
        int[] b = Arrays.copyOf(a,100);
        for (int i = 0; i < b.length; i++){
            System.out.println(b[i]);
        }

    }
}
